import csv

# 读取txt文件
with open(r"E:\trae\translate\4_河东区.txt", 'r', encoding='utf-8') as infile:
    lines = infile.readlines()

# 创建并打开一个新的csv文件进行写入
with open(r"E:\trae\translate\4_河东区.csv", 'w', newline='', encoding='utf-8') as outfile:
    writer = csv.writer(outfile)
    # 可选：写入表头
    writer.writerow(["地址", "经纬度"])

    # 逐行处理txt文件
    for line in lines:
        line = line.strip()
        if not line:  # 跳过空行
            continue
        
        parts = line.split(',')
        if len(parts) < 3:
            continue  # 如果这一行缺少数据就跳过，防止报错
        
        # 第一部分是地址，第二和第三部分是经纬度
        address = parts[0]
        lat_lng = ','.join(parts[1:])  # 将经纬度合并为一个字符串

        # 写入csv
        writer.writerow([address, lat_lng])
